/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package scapi.utilerias;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author emmanuel
 */
public class ServidorFactory {
    public static String ServidorCola = "servCola";
    public static String ServidorEmpenio = "servEmpenio";
    public static String ServidorCatalogoProducto = "servCProducto";
    public static String ServidorUsuario = "servAUsuario";
    public static String ServidorSesion = "servSesion";
    public static String ServidorSucursal ="servSuc";
    public static String ServidorPignorante = "servPign";
    public static String ServidorProducto = "servPro";
    public static String ServidorVentas = "servVentas";
    public static String ServidorReportes = "servReportes";

    public static Remote obtenerServidor(String nombre) throws RemoteException, NotBoundException, MalformedURLException{
       String url="localhost";
       int puerto = 1099;
        try {
            String nueURL[] = LeerConfiguracion.getConfig();
            if(nueURL != null){
              url = nueURL[0];
              puerto = Integer.parseInt(nueURL[1]);
            }
          Registry registro = LocateRegistry.getRegistry(url, puerto);
          return registro.lookup(nombre);
            

        } catch (FileNotFoundException ex) {
            Logger.getLogger(ServidorFactory.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ServidorFactory.class.getName()).log(Level.SEVERE, null, ex);
        }

   
        return null;
       //return Naming.lookup(url+nombre);
    }

}
